package com.lcsolute.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.lcsolute.constants.SystemConstants;
import com.lcsolute.dao.VideoDao;
import com.lcsolute.domain.ResponseResult;
import com.lcsolute.domain.entity.Video;
import com.lcsolute.domain.vo.HotVedioVo;
import com.lcsolute.service.VideoService;
import com.lcsolute.utils.BeanCopyUtils;
import org.apache.catalina.Host;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Videos)表服务实现类
 *
 * @author makejava
 * @since 2022-02-19 04:04:17
 */
@Service("videosService")
public class VideoServiceImpl extends ServiceImpl<VideoDao, Video> implements VideoService {
    @Override
    public ResponseResult hotVideoList() {
        LambdaQueryWrapper<Video> queryWrapper = new LambdaQueryWrapper<>();
        // 正式发布的视频
        queryWrapper.eq(Video::getStatus, SystemConstants.VIDEO_STATUS_NORMAL);
        // 安装点赞量进行排序
        queryWrapper.orderByDesc(Video::getLikeCounts);
        // 最多只查询 10 条
        Page<Video> page = new Page<>(SystemConstants.HOT_VIDEO_PAGE_First, SystemConstants.HOT_VIDEO_PAGE_SIZE);
        page(page, queryWrapper);

        List<Video> videos = page.getRecords();

        // bean 拷贝
        List<HotVedioVo> hotVedioVos = BeanCopyUtils.copyBeanList(videos, HotVedioVo.class);
        return ResponseResult.okResult(hotVedioVos);
    }
}
